//index.js
//获取应用实例
var app = getApp()
Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    productDefault:'嘟嘟',
    productName:'',
    schollDefault:'清华园小学',
    schollName:'',
    schollArr:["南京一中","南京二中","南京三中","南京四中","南京五中"],
    schollIndex:0
  },
  setName:function(e){
    this.setData({
      productName:e.detail.value     
    })
    
  },
  clearName:function(){
    this.setData({
      productName:''
    })
  },
  setScholl:function(e){
    this.setData({
      schollName:e.detail.value     
    })
    
  },
  clearScholl:function(){
    this.setData({
      schollName:''
    })
  },
  selectScholl:function(e){
   // console.log(e.detail.value)
    this.setData({
      schollIndex:e.detail.value
    })

  },
  setMsg: function(e) { //提交数据
    var goods=e.detail.value.goods; //宝贝
    var scholl=e.detail.value.scholl;//就读学校
    var schollClass=this.data.schollArr[e.detail.value.schollClass];//所属年级
    if(!goods){
      wx.showModal({
        title: "提示",
        content: "宝贝不能为空",
        showCancel: false,
        confirmText: "确定"
      })
      return false;
    }
    if(!scholl){
      wx.showModal({
        title: "提示",
        content: "就读学校不能为空",
        showCancel: false,
        confirmText: "确定"
      })
      return false;
    }
    
    console.log('form发生了submit事件，携带数据为：', e.detail.value)
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function () {
    console.log('onLoad')
    var that = this
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function(userInfo){
      //更新数据
      that.setData({
        userInfo:userInfo
      })
    })
  }
})
